<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/XGameAdmin_template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>XGame</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->

<!-- InstanceEndEditable -->
<link type="text/css" rel="stylesheet" href="CSS/adminCSS.css" />
</head>
<?php
include('admin_lock.php');

if($_SERVER["REQUEST_METHOD"] == "POST")
{
	if(!empty($_POST['removeID']))
	{
		$id = addslashes($_POST['removeID']);
		$sql="DELETE FROM stock where stock_ID = $id";
		mysql_query($sql);
	}
	else if(!empty($_POST['updateID']))
	{
		
		if(empty($_POST['quantity']))
		{
			$quantity=0;
		}else
		{
			$quantity=addslashes($_POST['quantity']);
		}
		$id = addslashes($_POST['updateID']);
		$sql="UPDATE stock SET game_stock='$quantity' Where stock_ID = '$id'";
		mysql_query($sql);
	}
}
$q="Select * FROM stock";
$result=mysql_query($q);
?>
<body>
<div id="container">

<div id="wrapper">

<div id="banner">
<ul class="topLink">
<li> Welcome, Admin </li>
<li> <a href="Logout.php"> Logout </a> </li>
</ul>


<img src="Assets/XGame.png" alt="XGame" />
</div>

<div id="menu">

<ul class="nav">
<li> <a href="AdminMember.php"> Member </a> </li>
<li> <a href="AdminNews.php"> News </a> </li>
<li> <a href="AdminGames.php"> Games </a> </li>
<li> <a href="AdminStock.php"> Stock </a> </li>
<li> <a href="AdminOrder.php"> Order </a> </li>
<li> <a href="AdminHistory.php"> History </a> </li>
</ul>

</div>

<div id="main">
<!-- InstanceBeginEditable name="Main" -->
<table border="0" class="table" width="750px">
<tr align="center">
<th class="tableHeader"> Stock ID </th>
<th class="tableHeader"> Product ID </th>
<th class="tableHeader"> Quantity </th>
<th class="tableHeader"> Location </th>
<th colspan="2" class="tableHeader"> Action </th>
</tr>

<?php
while($data_fetch=mysql_fetch_array($result))
{

echo "<tr align='center'>";
echo "<td class='tableContent'>". $data_fetch['stock_ID'] ."</td>";
$id = $data_fetch['stock_ID'];
$gid = $data_fetch['game_ID'];
$gamename = mysql_query("SELECT demo_name FROM demo WHERE demo_ID=$gid");
$gamename = mysql_fetch_assoc($gamename);
echo "<td class='tableContent'>". $gamename['demo_name'] ."</td>";
?>
<form name="update" method="POST">
<td class='tableContent'> <input type='text' name='quantity' size='5' value='<?php echo $data_fetch['game_stock']; ?>'/></td>
<?php
$lid = $data_fetch['location_ID'];
$location = mysql_query("SELECT location_name FROM location WHERE location_ID=$lid");
$location = mysql_fetch_assoc($location);
echo "<td class='tableContent'>". $location['location_name'] ."</td>";
?>

<td class='tableContent'> 
<input type="hidden" name="updateID" value="<?php echo "$id"; ?>"/>
<input type="submit" onClick="window.location.href=window.location.href" name="update" value="Update"/>
</td>
</form>

<td class='tableContent'> 
<form name="remove" method="POST">
<input type="hidden" name="removeID" value="<?php echo "$id"; ?>"/>
<input type="submit" onClick="window.location.href=window.location.href" name="remove" value="Remove"/>
</form>
</td>


<?php
echo "</tr>";

}
?>
</table>
<br />

<form align="center" name="new" action="NewStock.php">
<input type="submit" name="new" value="Add New Stock"/>
</form>

<!-- InstanceEndEditable -->
</div>

<div id="footer">
<p align="center"> &copy; &nbsp; 2012 XGame </p>
</div>

</div>

</div>

</body>
<!-- InstanceEnd --></html>
